﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BGM_Project_Control_Expense.aspx.cs" Inherits="KPIS.GERP.GBMS.APP_UI.Form.BGM_Project_Control_Expense" %>

<%@ Register src="../Controls/Combo/SourceCombo.ascx" tagname="SourceCombo" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <title><asp:Literal runat="Server" id="litTitle"/></title>
</head>
<body>
    <form id="form1" runat="server">
        <link rel="StyleSheet" href="../../Styles/StyleSheet.css" type="text/css" />
        
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager> 
        
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" BackgroundPosition="None" Transparency="100">
        </telerik:RadAjaxLoadingPanel>

        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="cbSource">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="cbSource" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="gridExpense" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="rpProjControl" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="pnAdd" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="gridExpense">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="gridExpense" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="rpProjControl" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="pnAdd" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="cmdInsert">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="gridExpense" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="rpProjControl" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="pnAdd" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="cmdCancel">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="gridExpense" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="rpProjControl" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="pnAdd" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>    
                
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function isNumberKey(event) 
                {
                    var charCode = (event.which) ? event.which : event.keyCode
                    if(charCode > 31 && (charCode < 48 || charCode > 57)){
                        return false;
                    }
                    return true;
                }

                function onTextChange(sender) {
                    if (sender.get_value() == "") {
                        sender.set_text("");
                    }
                }
            </script>
        </telerik:RadCodeBlock>

        <div class="defaultFont">
            <div class="header-grid">
                <table style="padding: 5px; font-family: 'Segoe UI'; font-size: 13px; font-weight: normal;">
                    <tr>
                        <td width="100px">
                            กิจกรรมย่อย :
                        </td>
                        <td width="300px">
                            <asp:Label ID="lbSubActName" runat="server" ForeColor="Blue" />
                            <input id="hSubActSeq" runat="server" type="hidden" />
                        </td>
                        <td width="100px">
                            หน่วยงาน :
                        </td>
                        <td>
                            <asp:Label ID="lbJobsiteName" runat="server" ForeColor="Blue" />
                            <input id="hJobsiteSeq" runat="server" type="hidden" />
                            <input id="hBgmYear" runat="server" type="hidden" />
                        </td>
                    </tr>
                    <tr>
                        <td width="100px">
                            แหล่งเงิน :
                        </td>
                        <td colspan="3">
                            <telerik:RadComboBox runat="server" ID="cbSource" AutoPostBack="true"
                                DataTextField="text" DataValueField="value" Width="250px" 
                                onselectedindexchanged="cbSource_SelectedIndexChanged">
                            </telerik:RadComboBox>
                        </td>
                    </tr>
                </table>
            </div>
                    
            <table>
                <tr>
                    <td>
                        <asp:Panel ID="pnGridExpense" runat="server" width="840px">
                            <asp:Label ID="lbProjectID" runat="server" Visible="false"></asp:Label>
                            <table>
                                <tr>
                                    <td>
                                        <table>
                                            <tr>
                                                <td valign="top" height="25px">
                                                    <asp:Label ID="lbProjectName" runat="server" Font-Bold="True" ForeColor="#0066FF" Font-Size="Large"></asp:Label>
                                                </td>
                                            </tr>
                                        </table>
                                        <telerik:RadGrid GroupingSettings-CaseSensitive="false" ID="gridExpense" runat="server" AllowFilteringByColumn="True" 
                                            Font-Names="Segoe UI" Font-Size="13px" Height="340px"
                                            AllowMultiRowSelection="false" AutoGenerateColumns="False"
                                            GridLines="None" MasterTableView-GridLines="None" Width="580px" 
                                            OnNeedDataSource="gridExpense_NeedDataSource" 
                                            OnItemCommand="gridExpense_ItemCommand"
                                            OnItemDataBound="gridExpense_ItemDataBound">
                                            <mastertableview commanditemdisplay="None" datakeynames="bgm_proj_exp_seq" grouploadmode="Client"
                                                NoDetailRecordsText="... ไม่มีข้อมูล ..." GroupsDefaultExpanded="true">
                                                <Columns>
                                                    <telerik:GridBoundColumn visible="false" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderText="รหัสค่าใช้จ่าย" ItemStyle-HorizontalAlign="Left" DataField="bgm_exp_seq"
                                                        UniqueName="bgm_exp_seq" >
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn visible="false"
                                                        DataField="prj_type_seq" UniqueName="prj_type_seq" >
                                                    </telerik:GridBoundColumn> 
                                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" 
                                                        CurrentFilterFunction="Contains" DataField="bgm_exp_name" 
                                                        FilterControlWidth="100%" HeaderStyle-HorizontalAlign="Center" 
                                                        HeaderText="ค่าใช้จ่าย" ShowFilterIcon="false" UniqueName="bgm_exp_name"
                                                        HeaderStyle-Width="370px" >
                                                        <HeaderStyle HorizontalAlign="Center" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridTemplateColumn HeaderStyle-Width="150px" ShowFilterIcon="false" AllowFiltering="false" UniqueName="total_amount"
                                                        HeaderStyle-HorizontalAlign="Center" HeaderText="คงเหลือ(บาท)" ItemStyle-HorizontalAlign="Right"> 
                                                        <ItemTemplate>
                                                            <asp:Label ID="lbTotalAmount" runat="server" Text='<%# Eval("total_amount", "{0:n2}") %>'></asp:Label>
                                                            <asp:Label ID="lbTotalAmountOutPlan" runat="server" Text='<%# "[" + Eval("total_amount_out_plan", "{0:n2}") + "]" %>' Visible="false" ForeColor="Red"></asp:Label>
                                                            <asp:ImageButton ID="cmdPlus" runat="server" ImageUrl="../Image/Grid/back.gif" ToolTip="ดึงเงินจากกองกลาง" CommandName="Plus" />
                                                            <asp:ImageButton ID="cmdMinus" runat="server" ImageUrl="../Image/Grid/forward red.gif" ToolTip="คืนเงินเข้ากองกลาง" CommandName="Minus" />
                                                        </ItemTemplate>
                                                        <HeaderStyle HorizontalAlign="Center" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridBoundColumn visible="false" UniqueName="bgm_proj_exp_seq" DataField="bgm_proj_exp_seq">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn visible="false" UniqueName="bgm_exp_grp_seq" DataField="bgm_exp_grp_seq">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn visible="false" UniqueName="bgm_exp_grp_name" DataField="bgm_exp_grp_name">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn visible="false" UniqueName="total_amount" DataField="total_amount">
                                                    </telerik:GridBoundColumn>
                                                </Columns>
                                                <groupbyexpressions>
                                                    <telerik:GridGroupByExpression>
                                                        <groupbyfields>
                                                            <telerik:GridGroupByField FieldName="bgm_exp_grp_seq" HeaderText="" />
                                                        </groupbyfields>
                                                        <selectfields>
                                                            <telerik:GridGroupByField FieldName="bgm_exp_grp_name" HeaderText="งบรายจ่าย : " HeaderValueSeparator="" />
                                                        </selectfields>
                                                    </telerik:GridGroupByExpression>
                                                    <telerik:GridGroupByExpression>
                                                        <groupbyfields>
                                                            <telerik:GridGroupByField FieldName="bgm_exp_seq_2" HeaderText="" />
                                                        </groupbyfields>
                                                        <selectfields>
                                                            <telerik:GridGroupByField FieldName="bgm_exp_name_2" HeaderText="หมวดค่าใช้จ่าย : " HeaderValueSeparator="" />
                                                        </selectfields>
                                                    </telerik:GridGroupByExpression>
                                                    <telerik:GridGroupByExpression>
                                                        <groupbyfields>
                                                            <telerik:GridGroupByField FieldName="bgm_exp_seq_1" HeaderText="" />
                                                        </groupbyfields>
                                                        <selectfields>
                                                            <telerik:GridGroupByField FieldName="bgm_exp_name_1" HeaderText="รายการรายจ่าย : " HeaderValueSeparator="" />
                                                        </selectfields>
                                                    </telerik:GridGroupByExpression>
                                                </groupbyexpressions>
                                            </mastertableview>
                                        <clientsettings EnableRowHoverStyle="true">
                                            <clientevents />
                                                <selecting AllowRowSelect="True" />
                                                <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                                            </clientsettings>
                                        </telerik:RadGrid>
                                    </td>
                                    <td valign="top">
                                        <div style="margin-left: 5px;">
                                            <asp:Repeater ID="rpProjControl" runat="server">
                                                <HeaderTemplate>
                                                    <div class="DivInfo">
                                                        จำนวนเงินคงเหลือกองกลาง
                                                    </div>
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <table width="240px">
                                                        <tr>
                                                            <td width="100px">
                                                                <%# Eval("bgm_exp_grp_name") %>
                                                            </td>
                                                            <td align="right">
                                                                <asp:Label ID="lbAmount" runat="server" ForeColor="Blue" Text='<%# Eval("amount", "{0:n2}") %>' />
                                                                <input ID="lbBgmProjCtrlSeq" runat="server" type="hidden" value='<%# Eval("bgm_proj_ctrl_seq") %>' />
                                                                <input ID="lbBgmExpGrpSeq" runat="server" type="hidden" value='<%# Eval("bgm_exp_grp_seq") %>' />
                                                            </td>
                                                            <td width="20px">
                                                                &nbsp;บาท
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                            <div class="DivInfo">
                                                &nbsp;
                                            </div>
                                            <asp:Panel ID="pnAdd" runat="server" Width="240px" BorderStyle="Solid" BorderColor="#FF6600" BorderWidth="1px" HorizontalAlign="Center">
                                                <table>
                                                    <tr>
                                                        <td align="left" width="200px" style="border-bottom-width: 1px; border-bottom-color: #CCCCCC; border-bottom-style: groove; padding-left: 5px; padding-bottom: 2px; padding-top: 15px; font-weight: bold; color: #FF6600;">
                                                            <asp:Label ID="lbMode" runat="server" Text="ดึงเงินจากกองกลาง" />
                                                            <asp:Label ID="lbBgmProjCtrlSeq" runat="server" Visible="false" />
                                                            <asp:Label ID="lbBgmProjExpSeq" runat="server" Visible="false" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left" width="200px" style="border-bottom-width: 1px; border-bottom-color: #CCCCCC; border-bottom-style: groove; padding-left: 5px; padding-bottom: 2px; padding-top: 5px;">
                                                            <asp:Label ID="lbBgmExpName" runat="server" ForeColor="Blue" />
                                                            <asp:Label ID="lbBgmExpSeq" runat="server" Visible="false" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left" width="200px" style="border-bottom-width: 1px; border-bottom-color: #CCCCCC; border-bottom-style: groove; padding-left: 5px; padding-bottom: 2px; padding-top: 5px;">
                                                            <asp:Label ID="lbBgmExpGrpName" runat="server" ForeColor="Blue" />
                                                            <asp:Label ID="lbBgmExpGrpSeq" runat="server" Visible="false" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left" width="200px" style="border-bottom-width: 1px; border-bottom-color: #CCCCCC; border-bottom-style: groove; padding-left: 5px; padding-bottom: 2px; padding-top: 5px;">
                                                            กรอกจำนวนเงิน <telerik:RadNumericTextBox ID="txtTotalAmount" runat="server" CssClass="RadNumericTextBox" Width="100px" />
                                                            <asp:Label ID="lbAmount" runat="server" Visible="false" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="center" width="200px" style="padding-left: 5px; padding-bottom: 2px; padding-top: 5px;padding-bottom: 15px;">
                                                            <asp:LinkButton ID="cmdInsert" runat="server" Text="ดึงเงินจากกองกลาง" OnClick="cmdInsert_Click" />&nbsp;
                                                            <asp:LinkButton ID="cmdCancel" runat="server" Text="ยกเลิก" OnClick="cmdCancel_Click" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="center">
                                                            <asp:Label ID="lbError" runat="server" ForeColor="Red" Text="จำนวนเงินเกินกว่าที่ทำรายการได้" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </asp:Panel>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
